<script>

import { mapGetters } from 'vuex'
export default {
  name: "Tabbar",
  props: {
    path: {
      type: String,
      default: ''
    },
    count: {
      type: Number,
      default: 0
    }
  },
  watch: {
    count: {
      handler(val) {
        // this.userList.forEach(item => {
        //   if (item.pagePath === this.path) {
        //     item.count = val || 0
        //   }
        // })
      },
      immediate: true
    }
  },
  data() {
    return {
      select: 0,
      userList: [
        {
          iconPath: "/static/tabbar/task.png",
          selectedIconPath: "/static/tabbar/task_active.png",
          text: '任务大厅',
          pagePath: '/pages/task/index',
          count: 0
        },
        {
          iconPath: "/static/tabbar/user.png",
          selectedIconPath: "/static/tabbar/user_active.png",
          text: '个人中心',
          pagePath: '/pages/my/index'
        },
      ],
      adminList: [
        {
          iconPath: "/static/tabbar/task.png",
          selectedIconPath: "/static/tabbar/task_active.png",
          text: '任务大厅',
          pagePath: '/pages/task/index',
          count: 0
        },
        {
          iconPath: "/static/tabbar/task.png",
          selectedIconPath: "/static/tabbar/task_active.png",
          text: '我的派单',
          pagePath: '/pages/task/dispatch',
          count: 0
        },
        {
          iconPath: "/static/tabbar/user.png",
          selectedIconPath: "/static/tabbar/user_active.png",
          text: '个人中心',
          pagePath: '/pages/my/index'
        },
      ],
      auditList: [
        {
          iconPath: "/static/tabbar/task.png",
          selectedIconPath: "/static/tabbar/task_active.png",
          text: '任务大厅',
          pagePath: '/pages/task/index',
          count: 0
        },
        {
          iconPath: "/static/tabbar/task.png",
          selectedIconPath: "/static/tabbar/task_active.png",
          text: '派单审核',
          pagePath: '/pages/task/audit',
          count: 0
        },
        {
          iconPath: "/static/tabbar/user.png",
          selectedIconPath: "/static/tabbar/user_active.png",
          text: '个人中心',
          pagePath: '/pages/my/index'
        },
      ]
    }
  },
  methods: {
    changeTabBar(index) {
      let path = this.tabbarList[index].path
      uni.navigateTo({
        url: path
      })
    }
  },
  computed: {
    ...mapGetters(['userInfo', 'role']),
    tabbarList() {
      console.log(this.role, 'role')
      if (this.userInfo.role === 0) {
        if (this.userInfo.is_audit) {
          return this.auditList
        } else {
          return this.userList
        }
      } else {
        return this.adminList
      }
    }
  }
}
</script>

<template>
  <u-tabbar height="60px" v-model="select" :list="tabbarList" @change="changeTabBar"></u-tabbar>
</template>

<style scoped lang="scss">

</style>
